#!/usr/bin/env ruby

require 'bundler/setup'
require 'ruby_event_store/profiler'
require 'ruby_event_store'
require 'active_support/notifications'
require 'aggregate_root'

asn = ActiveSupport::Notifications
event_store = RubyEventStore::Client.new(
  repository: RubyEventStore::InstrumentedRepository.new(RubyEventStore::InMemoryRepository.new, asn),
  mapper: RubyEventStore::Mappers::InstrumentedMapper.new(RubyEventStore::Mappers::Default.new, asn),
  dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::Dispatcher.new, asn)
)
DummyEvent  = Class.new(RubyEventStore::Event)
repo  = AggregateRoot::InstrumentedRepository.new(AggregateRoot::Repository.new(event_store), asn)

class Bazinga
  include AggregateRoot

  def do_the_dummy
    apply(DummyEvent.new)
  end

  on DummyEvent do |event|
  end
end


RubyEventStore::Profiler.new(asn).measure do
  aggregate = repo.load(Bazinga.new, 'bazinga')
  100.times { aggregate.do_the_dummy }
  repo.store(aggregate, 'bazinga')
end
